using System;
using System.Collections.Generic;
using System.Text;
using FlatRedBall;
using FlatRedBall.Input;
using FlatRedBall.AI.Pathfinding;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Graphics.Particle;

using FlatRedBall.Graphics.Model;
using FlatRedBall.Math.Geometry;
using FlatRedBall.Math.Splines;

using Cursor = FlatRedBall.Gui.Cursor;
using GuiManager = FlatRedBall.Gui.GuiManager;
using FlatRedBall.Localization;
using GameTime = Microsoft.Xna.Framework.GameTime;

#if FRB_XNA || SILVERLIGHT
using Keys = Microsoft.Xna.Framework.Input.Keys;
using Vector3 = Microsoft.Xna.Framework.Vector3;
using Texture2D = Microsoft.Xna.Framework.Graphics.Texture2D;
#endif

namespace NereusGame.Screens
{
	public partial class LoadScreen
	{
        private Sprite backGround;
        private Sprite spinningSprite;       // logo which has rotation animation
        private Sprite continueSprit;

        

		void CustomInitialize()
		{
            ResetCamera();
            InitializeBackground();
            InitializeLoadingScreen();
  		}

		void CustomActivity(bool firstTimeCalled)
		{
            //if (InputManager.BackPressed)
            //{
            //    // destroy crrent screen
            //    if (AsyncLoadingState == AsyncLoadingState.Done)
            //    {
            //        if (InputManager.TouchScreen.ScreenPushed)
            //        {
            //            MoveToScreen(typeof(Menu).FullName);
            //        }

            //    }

            //}

            LoadingActivity();
		}

		void CustomDestroy()
		{
            SpriteManager.RemoveSprite(backGround);
            SpriteManager.RemoveSprite(spinningSprite);
            SpriteManager.RemoveSprite(continueSprit);

		}

        static void CustomLoadStaticContent(string contentManagerName)
        {
            

        }


//***************************************************INITIALIZE**********************************************************
        private void InitializeLoadingScreen()
        {
            // set the position of the camera
            SpriteManager.Camera.Position = Vector3.Zero;
            SpriteManager.Camera.Position.Z = 40f;
            
            // intialize the spinnig logo
            spinningSprite = new Sprite();
            SpriteManager.AddSprite(spinningSprite);
            spinningSprite.Texture = Logo;
            spinningSprite.ScaleY = 2f;
            spinningSprite.ScaleX = 2f;
            spinningSprite.Z = 1;
            spinningSprite.Position = new Vector3(-SpriteManager.Camera.XEdge / 3f, -SpriteManager.Camera.YEdge / 3f, 0);
            spinningSprite.RotationYVelocity = 1f;


            //tap to continue
            continueSprit = SpriteManager.AddSprite(@"Content\Screens\LoadScreen\tapToContinue.png", "Global");
            continueSprit.ScaleY = SpriteManager.Camera.YEdge / 20;
            continueSprit.ScaleX = 5f * continueSprit.ScaleY;
            continueSprit.X = 15.0f;
            continueSprit.Y = -14;
            continueSprit.Z = -1;
            continueSprit.Visible = false;
        }

//***************************************************ACTIVITY**********************************************************
        private void LoadingActivity()
        {
            // start lading next level1
            if (AsyncLoadingState == AsyncLoadingState.NotStarted)
            {
                StartAsyncLoad(typeof(Level1Sol).FullName);
            }

            // destroy crrent screen
            if (AsyncLoadingState == AsyncLoadingState.Done)
            {
                ShowStartButton();  // show the start button

                // if any player press A go to level1 
                if (InputManager.TouchScreen.ScreenPushed)
                {
                    MoveToScreen(typeof(Level1Sol).FullName);
                }
                
            }
        }

        // show the start button
        private void ShowStartButton()
        {
            continueSprit.Visible = true; ;
        }

        private void ResetCamera()
        {
            // reset camera position
            SpriteManager.Camera.Position = SpriteManager.Camera.Velocity = SpriteManager.Camera.Acceleration = Vector3.Zero;
            SpriteManager.Camera.Position.Z = 40f;
        }

        // setup background for this screen
        private void InitializeBackground()
        {
            backGround = new Sprite();
            backGround.Texture = LoadingScreen;
            SpriteManager.AddSprite(backGround);
            backGround.ScaleX = SpriteManager.Camera.XEdge / 2.35f;  // magic numbers are here to make the image fit the screen LOL
            backGround.ScaleY = SpriteManager.Camera.YEdge / 2.35f;  // magic numbers are here to make the image fit the screen LOL
            backGround.Z = -2;
        }
	}



}